import cityPaySelector from './cityPaySelector';
import incityNumberSelector from './incityNumberSelector';
import incityRedMoneySelector from './incityRedMoneySelector';
import incityTimeSelector from './incityTimeSelector';
import incityChargesDetailsSelector from './incityChargesDetailsSelector';
import incityUnpaidChargesDetailsSelector from './incityUnpaidChargesDetailsSelector';
import incityValuationRulesSelector from './incityValuationRulesSelector';
import incityChangeValuationRulesSelector from './incityChangeValuationRulesSelector';
import incityCouponSelector from './incityCouponSelector';
import incityEvaluateSelector from './incityEvaluateSelector';
import incityEvaluateSeeSelector from './incityEvaluateSeeSelector';
import incityTripSelector from './incityTripSelector';
import SearchBox from './search/SearchBox';
import store from '@/store';
import router from '@/router';
import Vue from 'vue';
const CityPaySelector = Vue.extend(cityPaySelector);
const IncityNumberSelector = Vue.extend(incityNumberSelector);
const IncityRedMoneySelector = Vue.extend(incityRedMoneySelector);
const IncityTimeSelector = Vue.extend(incityTimeSelector);
const SearchBoxConstructor = Vue.extend(SearchBox);
const IncityChargesDetailsSelector = Vue.extend(incityChargesDetailsSelector);
const IncityUnpaidChargesDetailsSelector = Vue.extend(
  incityUnpaidChargesDetailsSelector
);
const IncityValuationRulesSelector = Vue.extend(incityValuationRulesSelector);
const IncityChangeValuationRulesSelector = Vue.extend(
  incityChangeValuationRulesSelector
);
const IncityCouponSelector = Vue.extend(incityCouponSelector);
const IncityEvaluateSelector = Vue.extend(incityEvaluateSelector);
const IncityEvaluateSeeSelector = Vue.extend(incityEvaluateSeeSelector);
const IncityTripSelector = Vue.extend(incityTripSelector);
function createVM(constructor, opt) {
  return new Promise((resolve, reject) => {
    let params = {
      value: true
    };
    Object.assign(params, opt);
    let vm = new constructor({
      propsData: params,
      store,
      router
    }).$mount();
    if (vm) {
      vm.$on('cancel', () => {
        vm.$destroy();
        reject();
      });
      vm.$on('submit', data => {
        resolve(data);
        vm.$destroy();
      });
    }
  });
}
const Popup = {
  createCityPaySelector() {
    return createVM(CityPaySelector);
  },
  createCityNumberSelector() {
    return createVM(IncityNumberSelector);
  },
  createCityRedMoneySelector() {
    return createVM(IncityRedMoneySelector);
  },
  createIncityTimeSelector() {
    return createVM(IncityTimeSelector);
  },
  selectStartPosition(startOk) {
    return createVM(SearchBoxConstructor, {
      isStart: true,
      startOk: startOk
    });
  },
  selectEndPosition() {
    return createVM(SearchBoxConstructor, { isStart: false });
  },
  createIncityChargesDetailsSelector() {
    return createVM(IncityChargesDetailsSelector);
  },
  createIncityUnpaidChargesDetailsSelector() {
    return createVM(IncityUnpaidChargesDetailsSelector);
  },
  createIncityValuationRulesSelector() {
    return createVM(IncityValuationRulesSelector);
  },
  createIncityChangeValuationRulesSelector() {
    return createVM(IncityChangeValuationRulesSelector);
  },
  createIncityCouponSelector() {
    return createVM(IncityCouponSelector);
  },
  createIncityEvaluateSelector() {
    return createVM(IncityEvaluateSelector);
  },
  createIncityEvaluateSeeSelector() {
    return createVM(IncityEvaluateSeeSelector);
  },
  createIncityTripSelector() {
    return createVM(IncityTripSelector);
  }
};
export default Popup;
